# !/usr/bin/env python
# -*-coding:utf-8 -*-

"""
# File       : utils.py
# Time       ：2022/11/20 16:59
# Author     ：hhs
# version    ：python 3.6
# Description：通用工具
"""
from django.utils.deprecation import MiddlewareMixin

from common.result import fail


def require_login(f):
    def inner(*args, **kwargs):
        request = args[1]
        if not request.user.id:
            return fail("请先登录！")  # 等静态页面写好可以直接重定向到静态页面
        return f(*args, **kwargs)
    return inner


class DisableCSRF(MiddlewareMixin):
    def process_request(self, request):
        setattr(request, '_dont_enforce_csrf_checks', True)
